package worldinruin.gui.imp;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import worldinruin.GameDataHandler;
import worldinruin.core.imp.ResourceTypes;
import worldinruin.resources.IconMap;
import worldinruin.resources.Panels;
import worldinruin.utils.ResizableLabel;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MainMenuPanel extends javax.swing.JPanel implements ActionListener{
	private JButton newGameButton;
	private JButton loadGameButton;
	private JLabel wallpaperLabel;
	private JPanel buttonPanel;
	private JButton exitProgramButton;
	private JButton settingsButton;
	private JButton mapEditorButton;
	private JButton creditsButton;

	/**
	 * Creates a mainmenupanel with different options.
	 */
	public MainMenuPanel() {
		super();
		initGUI();
	}
	
	/**
	 * Initializes the mainmenupanel.
	 */
	private void initGUI() {
		try {
			setPreferredSize(new Dimension(400, 300));
			AnchorLayout anchorLayout = new AnchorLayout();
			this.setLayout(anchorLayout);
			this.setVerifyInputWhenFocusTarget(false);
			{
				wallpaperLabel = new ResizableLabel(IconMap.getInstance().getIcon(ResourceTypes.WALLPAPER).getImage());
				this.add(wallpaperLabel, new AnchorConstraint(1, 1003, 1001, 1, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				wallpaperLabel.setLayout(new AnchorLayout());
			}
			{
				buttonPanel = new JPanel();
				AnchorLayout buttonPanelLayout = new AnchorLayout();
				wallpaperLabel.add(buttonPanel, new AnchorConstraint(188, 638, 908, 321, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				buttonPanel.setLayout(buttonPanelLayout);
				buttonPanel.setPreferredSize(new java.awt.Dimension(127, 216));
				buttonPanel.setOpaque(false);
				{
					newGameButton = new JButton();
					buttonPanel.add(newGameButton, new AnchorConstraint(81, 901, 178, 98, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					FlowLayout newGameButtonLayout = new FlowLayout();
					newGameButtonLayout.setAlignOnBaseline(true);
					newGameButtonLayout.setVgap(100);
					newGameButtonLayout.setHgap(10);
					newGameButton.setText(Messages.getString("MainMenuPanel.0")); //$NON-NLS-1$
					newGameButton.setLayout(newGameButtonLayout);
					newGameButton.setPreferredSize(new java.awt.Dimension(102, 21));
					newGameButton.addActionListener(this);
				}
				{
					loadGameButton = new JButton();
					buttonPanel.add(loadGameButton, new AnchorConstraint(229, 901, 326, 98, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					FlowLayout loadGameButtonLayout = new FlowLayout();
					loadGameButtonLayout.setAlignOnBaseline(true);
					loadGameButtonLayout.setVgap(100);
					loadGameButtonLayout.setHgap(10);
					loadGameButton.setText(Messages.getString("MainMenuPanel.1")); //$NON-NLS-1$
					loadGameButton.setLayout(loadGameButtonLayout);
					loadGameButton.setPreferredSize(new java.awt.Dimension(102, 21));
				}
				{
					mapEditorButton = new JButton();
					buttonPanel.add(mapEditorButton, new AnchorConstraint(386, 901, 483, 98, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					FlowLayout mapEditorButtonLayout = new FlowLayout();
					mapEditorButtonLayout.setAlignOnBaseline(true);
					mapEditorButtonLayout.setVgap(100);
					mapEditorButtonLayout.setHgap(10);
					mapEditorButton.setText(Messages.getString("MainMenuPanel.2")); //$NON-NLS-1$
					mapEditorButton.setLayout(mapEditorButtonLayout);
					mapEditorButton.setPreferredSize(new java.awt.Dimension(102, 21));
				}
				{
					settingsButton = new JButton();
					buttonPanel.add(settingsButton, new AnchorConstraint(543, 901, 641, 98, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					FlowLayout settingsButtonLayout = new FlowLayout();
					settingsButtonLayout.setAlignOnBaseline(true);
					settingsButtonLayout.setVgap(100);
					settingsButtonLayout.setHgap(10);
					settingsButton.setText(Messages.getString("MainMenuPanel.3")); //$NON-NLS-1$
					settingsButton.setLayout(settingsButtonLayout);
					settingsButton.setPreferredSize(new java.awt.Dimension(102, 21));
				}
				{
					creditsButton = new JButton();
					buttonPanel.add(creditsButton, new AnchorConstraint(701, 901, 798, 98, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					FlowLayout creditsButtonLayout = new FlowLayout();
					creditsButtonLayout.setAlignOnBaseline(true);
					creditsButtonLayout.setVgap(100);
					creditsButtonLayout.setHgap(10);
					creditsButton.setText(Messages.getString("MainMenuPanel.4")); //$NON-NLS-1$
					creditsButton.setLayout(creditsButtonLayout);
					creditsButton.setPreferredSize(new java.awt.Dimension(102, 21));
				}
				{
					exitProgramButton = new JButton();
					buttonPanel.add(exitProgramButton, new AnchorConstraint(858, 901, 956, 98, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					exitProgramButton.setLayout(null);
					exitProgramButton.setText(Messages.getString("MainMenuPanel.5")); //$NON-NLS-1$
					exitProgramButton.setPreferredSize(new java.awt.Dimension(102, 21));
					exitProgramButton.addActionListener(this);
				}
				revalidate();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JButton button = (JButton) e.getSource();
		if (button == newGameButton){
			GameDataHandler.getInstance().getGui().showPage(Panels.CREATENEWGAMEPANEL.toString());
		}
		else if (button == exitProgramButton){
			System.exit(0);
		}
	}
}
